package cart

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"go.uber.org/zap"
	"homepage_srv/homepage"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartBatchDelLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartBatchDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartBatchDelLogic {
	return &CartBatchDelLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 批量删除购物车中的商品
func (l *CartBatchDelLogic) CartBatchDel(req *types.CartBatchDelRequest) (resp *types.Response, err error) {
	del, err := l.svcCtx.HomepageGrpc.CartBatchDel(l.ctx, &homepage.CartBatchDelRequest{
		UserId:  req.UserId,
		GoodIds: req.GoodId,
	})
	if err != nil {
		pkg.Error("删除失败", zap.Error(err))
		return nil, err
	}
	return respons.Success(del), nil
}
